<template>
  <div class="row justify-content-center">
    <div class="col-8">
      <form name="editForm" role="form" novalidate v-on:submit.prevent="save()">
        <h2 id="myapplication5App.userClass.home.createOrEditLabel" data-cy="UserClassCreateUpdateHeading">Create or edit a UserClass</h2>
        <div>
          <div class="form-group" v-if="userClass.id">
            <label for="id">ID</label>
            <input type="text" class="form-control" id="id" name="id" v-model="userClass.id" readonly />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-classId">Class Id</label>
            <input
              type="number"
              class="form-control"
              name="classId"
              id="user-class-classId"
              data-cy="classId"
              :class="{ valid: !$v.userClass.classId.$invalid, invalid: $v.userClass.classId.$invalid }"
              v-model.number="$v.userClass.classId.$model"
            />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-startTime">Start Time</label>
            <div class="d-flex">
              <input
                id="user-class-startTime"
                data-cy="startTime"
                type="datetime-local"
                class="form-control"
                name="startTime"
                :class="{ valid: !$v.userClass.startTime.$invalid, invalid: $v.userClass.startTime.$invalid }"
                :value="convertDateTimeFromServer($v.userClass.startTime.$model)"
                @change="updateInstantField('startTime', $event)"
              />
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-endTime">End Time</label>
            <div class="d-flex">
              <input
                id="user-class-endTime"
                data-cy="endTime"
                type="datetime-local"
                class="form-control"
                name="endTime"
                :class="{ valid: !$v.userClass.endTime.$invalid, invalid: $v.userClass.endTime.$invalid }"
                :value="convertDateTimeFromServer($v.userClass.endTime.$model)"
                @change="updateInstantField('endTime', $event)"
              />
            </div>
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-classNumber">Class Number</label>
            <input
              type="number"
              class="form-control"
              name="classNumber"
              id="user-class-classNumber"
              data-cy="classNumber"
              :class="{ valid: !$v.userClass.classNumber.$invalid, invalid: $v.userClass.classNumber.$invalid }"
              v-model.number="$v.userClass.classNumber.$model"
            />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-classStatus">Class Status</label>
            <input
              type="number"
              class="form-control"
              name="classStatus"
              id="user-class-classStatus"
              data-cy="classStatus"
              :class="{ valid: !$v.userClass.classStatus.$invalid, invalid: $v.userClass.classStatus.$invalid }"
              v-model.number="$v.userClass.classStatus.$model"
            />
          </div>
          <div class="form-group">
            <label class="form-control-label" for="user-class-course">Course</label>
            <select class="form-control" id="user-class-course" data-cy="course" name="course" v-model="userClass.course">
              <option v-bind:value="null"></option>
              <option
                v-bind:value="userClass.course && courseOption.id === userClass.course.id ? userClass.course : courseOption"
                v-for="courseOption in courses"
                :key="courseOption.id"
              >
                {{ courseOption.id }}
              </option>
            </select>
          </div>
        </div>
        <div>
          <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" v-on:click="previousState()">
            <font-awesome-icon icon="ban"></font-awesome-icon>&nbsp;<span>Cancel</span>
          </button>
          <button
            type="submit"
            id="save-entity"
            data-cy="entityCreateSaveButton"
            :disabled="$v.userClass.$invalid || isSaving"
            class="btn btn-primary"
          >
            <font-awesome-icon icon="save"></font-awesome-icon>&nbsp;<span>Save</span>
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
<script lang="ts" src="./user-class-update.component.ts"></script>
